const schemas: { [key: string]: any } = {};
import {request} from "../Request";

export const getSchema = <T = any>(url: string, loadingSetter: React.Dispatch<boolean>): Promise<T> => {
  const schema = schemas[url];
  if (schema) {
    return Promise.resolve(schema);
  } else {
    return request<T>(url, {
      loadingSetter: loadingSetter,
      errMsg: '获取配置错误'
    })
      .then((resp) => {
        schemas[url] = resp;
        return resp;
      })
  }
};
